<?php

/**
 * This is the model class for table "{{payment_method}}".
 *
 * The followings are the available columns in table '{{payment_method}}':
 * @property integer $payment_id
 * @property string $payment_currency
 * @property string $payment_name
 * @property string $payment_description
 * @property integer $weight
 * @property integer $status
 */
class PaymentMethod extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return PaymentMethod the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return '{{payment_method}}';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('payment_currency, payment_name, payment_description, weight', 'required'),
            array('weight, status', 'numerical', 'integerOnly' => true),
            array('payment_currency', 'length', 'max' => 3),
            array('payment_name', 'length', 'max' => 100),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('payment_id, payment_currency, payment_name, payment_description, weight, status', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'payment_id' => 'Payment',
            'payment_currency' => 'Payment Currency',
            'payment_name' => 'Payment Name',
            'payment_description' => 'Payment Description',
            'weight' => 'Weight',
            'status' => 'Status',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('payment_id', $this->payment_id);
        $criteria->compare('payment_currency', $this->payment_currency, true);
        $criteria->compare('payment_name', $this->payment_name, true);
        $criteria->compare('payment_description', $this->payment_description, true);
        $criteria->compare('weight', $this->weight);
        $criteria->compare('status', $this->status);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

    public static function convertUserState($data) {
        $image = ($data->status == ConstantDefine::USER_STATUS_ACTIVE) ? 'active' : 'disabled';
        return bu() . '/images/' . $image . '.png';
    }

}
